//
//  HCCallBackModel.m
//  HelloCall
//
//  Created by WangYongpeng on 13-11-16.
//  Copyright (c) 2013年 HC. All rights reserved.
//

#import "HCCallBackModel.h"
#import "HCNetworkManger.h"

@implementation HCCallBackInfo

@synthesize callBackId = m_callBackId;
@synthesize remark = m_remark;
@synthesize custId = m_custId;
@synthesize addUserId = m_addUserId;
@synthesize addDate = m_addDate;
@synthesize callBackDate = m_callBackDate;
@synthesize status = m_status;

- (void)dealloc
{
    self.remark = nil;
    self.custId = nil;
    self.addUserId = nil;
    self.addDate = nil;
    self.callBackDate = nil;
    
    [super dealloc];
}

@end

@interface HCCallBackModel()<HCNetworkObserver>

@property (nonatomic, retain)NSMutableArray* callBackList;

@end

@implementation HCCallBackModel

@synthesize callBackList = m_callBackList;

static HCCallBackModel* g_defaultModel = nil;

+ (HCCallBackModel*)defaultModel
{
    if (nil == g_defaultModel)
    {
        g_defaultModel = [[HCCallBackModel alloc] init];
    }
    
    return g_defaultModel;
}

- (id)init
{
    self = [super init];
    if (nil != self)
    {
        self.callBackList = [NSMutableArray arrayWithCapacity:0];
        
        [[HCNetworkManger shareManger] addObserver:self];
    }
    return self;
}

- (void)dealloc
{
    [[HCNetworkManger shareManger] removeObserver:self];
    g_defaultModel = nil;
    self.callBackList = nil;
    
    [super dealloc];
}

- (BOOL)addCallBackInfo:(HCCallBackInfo*)callBackInfo
{
    for (HCCallBackInfo* info in self.callBackList)
    {
        if (info.callBackId == callBackInfo.callBackId)
        {
            return NO;
        }
    }
    
    [self.callBackList addObject:callBackInfo];
    return YES;
}

- (NSArray*)getCallBackInfoByCustId:(NSString*)CusId
{
    NSMutableArray* array = [NSMutableArray arrayWithCapacity:0];
    
    for (HCCallBackInfo* info in self.callBackList)
    {
        if ([info.custId isEqualToString:CusId])
        {
            [array addObject:info];
        }
    }
    
    return array;
}

#pragma mark -- HCNetworkObserver
- (void)notifyNetworkMsg:(int)msgID data:(void*) data
{
    /*pause modify———————————————------
    switch (msgID)
    {
        case EQueryCallBackInfo:
        {
            queryCallBackInfoResp* resp = (queryCallBackInfoResp*)data;
            
            if (!resp->headResp.success)
            {
                //显示错误提示
                break;
            }
            
            for (int i = 0; i < resp->vecBean.size(); i++)
            {
                HCCallBackInfo* info = [[[HCCallBackInfo alloc] init] autorelease];
                
                info.callBackId = resp->vecBean.at(i).callBackId;
                info.custId = [NSString stringWithFormat:@"%d", resp->vecBean.at(i).custId];
                info.remark = [NSString stringWithUTF8String:resp->vecBean.at(i).remark.data()];
                info.addUserId = [NSString stringWithFormat:@"%d", resp->vecBean.at(i).user_id];
                info.status = resp->vecBean.at(i).status;
                NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
                [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                info.addDate = [dateFormatter dateFromString:[NSString stringWithUTF8String:resp->vecBean.at(i).add_time.data()]];
                info.callBackDate = [dateFormatter dateFromString:[NSString stringWithUTF8String:resp->vecBean.at(i).callBackTime.data()]];
                [dateFormatter release];
                
                [self addCallBackInfo:info];
            }
            
            [self sendDataUpdateEvent:msgID];
            break;
        }
        case EUpdateCallBackInfo:
        {
            break;
        }
        case ESetCallBackStatus:
        {
            break;
        }
        default:
            break;
    }
     pause modify———————————————————*/
}

@end
